<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Pragma" CONTENT="no-cache">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit">

		<%include("/common/include.html"){}%>
	</head>

	<body class="easyui-layout">
			<table id="dailyNursing_datagrid" class="easyui-datagrid" style="height:100%;">
		
			</table>
			<div id="dail_tb" >
			
				<label class="label-top" style="width: 100%; display: block;">日期</label>
				<input  id="dailyNursing_datebox" name="month"  class="easyui-datebox theme-textbox-radius"style="height: 32px; width: 212px; text-align: center" />
			
				<input name="organIds" id="organIds" type="hidden" value="${organization.ids! }">
			</div>
			
		
		<script type="text/javascript">
			$(document).ready(function () {
				dateFormatter();
				//加载数据表格
				loadTable();
				$('#dailyNursing_datebox').datebox({
					onChange: function(date){
						loadTable();
					}
				});
			});
			
			function  loadTable()
			{	
				var columnsAll = new Array();
				columnsAll.push({field:'customerid',title:'ids',align:'center',hidden:true});
				
				columnsAll.push({field:'firstdate',title:'进店日期',width:80,align:'center'});
				columnsAll.push({field:'firstweight',title:'最初体重（斤）',width:50,align:'center'});
				columnsAll.push({field:'standardweight',title:'标准体重（斤）',width:50,align:'center'});
				columnsAll.push({field:'delweight',title:'应减斤数（斤）',width:50,align:'center'});
				columnsAll.push({field:'ddcount',title:'当月到<br/>店次数',width:30,align:'center'});
				/*columnsAll.push({field:'gjweight',title:'当月目标',width:100,align:'center',
					formatter: function(value,row,index)
					{	
						if(value!=null){ return  value;}
						else{return row.thismonthaim="0";}
					}
				});*/
				columnsAll.push({field:'gjweight',title:'当月实<br/>减斤数',width:50,align:'center',
					formatter: function(value,row,index)
					{	
						if(value!=null){ return  value;}
						else{return row.thismonthactualreduction="0";}
					}
				});
				//columnsAll.push({field:'yieldrateofthismonthaim',title:'当月目标达成率',width:100,align:'center'});
				columnsAll.push({field:'customertype',title:'是否<br/>达标',width:30,align:'center',
					formatter: function(value,row,index)
					{	
						if(value=="2")
						{
							return  '<span style="color:#ff954e;">是</span>';
						}else
						{
							return  '否';
						}
						
					}
				});
				for(var n=1;n<32;n++){
					var nstr = n;
					if(n<10){
						nstr= '0'+n;
					}
					columnsAll.push({field:'weight'+nstr,title:n,width:50,align:'center',formatter: function(value,row,index){	
						/*if(value !=null){
							return  value;
						}*/
						
						
							var isdc='weightqk'+nstr;
							
							if(value !=null)
							{
								
								if(row.isdc>0)
								{
									return   "<span  style='color:green'>" + value + "<span>";
								}
								else if(row.isdc==0)
								{	
									return   "<span  style='color:#00CCFF'>" + value + "<span>";
								}
								else if(row.isdc>0)
								{
									return   "<span  style='color:red'>" + value + "<span>";
								}else
								{
									return   value ;
								}
							}
						}
					});
				}
				
				columnsAll.push({field:'organname',title:'机构名称',width:50,align:'center'});
				/*columnsAll.push({field:'customername',title:'姓名',width:100,align:'center',
					formatter: function(value,row,index)
					{	var ids = row.cusids;
						if(value==null)
						{
							return  row.cusname=" ";
						}
						else
						{
							return '<a href="#" style="color: blue;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
						}
					}
				});*/
				columnsAll.push({field:'phone',title:'手机',width:150,align:'center'});
				columnsAll.push({field:'hybh',title:'会员编号',width:50,align:'center'});
				columnsAll.push({field:'chargepersion',title:'负责人',width:100,align:'center'});
				var month = $("#dailyNursing_datebox").val();
				var organIds = $("#organIds").val();
				$('#dailyNursing_datagrid').datagrid({
					cls: "theme-datagrid",
					toolbar: '#dail_tb',
					  singleSelect:true,  
					  rownumbers: true,
					  
					  frozenColumns:[[
										{field:'customername',title:'姓名',width:100,align:'center',
											formatter: function(value,row,index)
											{	var ids = row.cusids;
												if(value==null)
												{
													return  row.cusname=" ";
												}
												else
												{
													return '<a href="#" style="color: blue;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
												}
											}
										}
					        	]],
					  columns:[columnsAll],
					  url: "${cxt!}/dailyNursing/getDailyNursingInfo",
					  queryParams: {
							'month': month,
							'organIds':organIds,
							'fzUser':'-1'
						},
//					  showFooter:true, 
//					  footer:footer,
					 /* onLoadSuccess: function (data) {
			           //合计
					   heji();
			          },*/
				});
			}
			function  heji()
			{	
					 var rows = $('#dailyNursing_datagrid').datagrid('getRows');
				
			         for(var i=1;i<9;i++)
			         {
			        	 $('#dailyNursing_datagrid').datagrid('mergeCells',{
			     			index: rows.length - i,
			     			field: 'organname',
			     			colspan:9 
			     		});
			         }
				
			}

			function searchFrom(){
				$('#dailyNursing_datagrid').datagrid('load',sy.serializeObject($form));
			}

			function  dateFormatter(){
				$('#dailyNursing_datebox').datebox({
				       //显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
				       onShowPanel: function () {
				          //触发click事件弹出月份层
				          span.trigger('click'); 
				          if (!tds)
				            //延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
				            setTimeout(function() { 
				                tds = p.find('div.calendar-menu-month-inner td');
				                tds.click(function(e) {
				                   //禁止冒泡执行easyui给月份绑定的事件
				                   e.stopPropagation(); 
				                   //得到年份
				                   var year = /\d{4}/.exec(span.html())[0] ,
				                   //月份
				                   //之前是这样的month = parseInt($(this).attr('abbr'), 10) + 1; 
				                   month = parseInt($(this).attr('abbr'), 10);  

							         //隐藏日期对象                     
							         $('#dailyNursing_datebox').datebox('hidePanel').datebox('setValue', year + '-' + month); 
				                 });
				             }, 0);
				        },
				            //配置parser，返回选择的日期
				            parser: function (s) {
				                if (!s) return new Date();
				                var arr = s.split('-');
				                return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
				            },
				            //配置formatter，只返回年月 之前是这样的d.getFullYear() + '-' +(d.getMonth()); 
				            formatter: function (d) { 
				                var currentMonth = (d.getMonth()+1);
				                var currentMonthStr = currentMonth < 10 ? ('0' + currentMonth) : (currentMonth + '');
				                return d.getFullYear() + '-' + currentMonthStr; 
				            }
				        });

				        //日期选择对象
				        var p = $('#dailyNursing_datebox').datebox('panel'), 
				        //日期选择对象中月份
				        tds = false, 
				        //显示月份层的触发控件
				        span = p.find('span.calendar-text'); 
				        var curr_time = new Date();

				        //设置前当月
				        $("#dailyNursing_datebox").datebox("setValue", myformatter(curr_time));
			    
			 
			}
			//格式化日期
			function myformatter(date) {
			    //获取年份
			    var y = date.getFullYear();
			    //获取月份
			    var m = date.getMonth() + 1;
			    return y + '-' + m;
			}

		</script>
	</body>
</html>